<?php


namespace api\controller;


use common\controller\VerifyController;
use common\service\BIService;
use support\ErrorCode;
use think\Request;

class BIController extends VerifyController
{

    /**
     * @var BIService
     */
    private $bIService;

    public function __construct()
    {
        parent::__construct();
        $this->bIService = BIService::getInstance();
    }

    /**
     * 进行中的项目
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function selectProject(Request $request)
    {
        $res = $this->bIService->selectProject();
        return json(success_response('', $res));
    }

    /**
     * 月度工时排行
     * @param Request $request
     * @return \think\Response
     */
    public function selectManHourRank(Request $request)
    {
        $res = $this->bIService->selectManHourRank();
        return json(success_response('', $res));
    }

    /**
     * 审核列表
     * @param Request $request
     * @return \think\Response
     */
    public function selectReviewList(Request $request)
    {
        $res = $this->bIService->selectReviewList($request->param());
        return json(success_response('', $res));
    }

    /**
     * 任务统计
     * @param Request $request
     * @return \think\Response
     */
    public function selectTaskStatistics(Request $request)
    {
        $res = $this->bIService->selectTaskStatistics();
        return json(success_response('', $res));
    }

    /**
     * 任务完成趋势数据
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function selectTaskDoneTrend(Request $request)
    {
        $res = $this->bIService->selectTaskDoneTrend();
        return json(success_response('', $res));
    }

    /**
     * 任务类型数量分布
     * @param Request $request
     * @return \think\Response
     */
    public function selectTaskCategorySpread(Request $request)
    {
        $res = $this->bIService->selectTaskCategorySpread();
        return json(success_response('', $res));
    }

    /**
     * 总花费工时
     * @param Request $request
     * @return \think\Response
     */
    public function selectAllProjectSpend(Request $request)
    {
        $res = $this->bIService->selectAllProjectSpend();
        return json(success_response('', $res));
    }

    /**
     * 工作地点 数据
     * @param Request $request
     * @return \think\Response
     */
    public function selectWorkBaseMap(Request $request)
    {
        $res = $this->bIService->selectWorkBaseMap();
        return json(success_response('', $res));
    }

    /**
     * 查询bi项目配置
     * @param Request $request
     * @return \think\Response
     */
    public function findConfig(Request $request)
    {
        $res = $this->bIService->findConfig($request->param());
        return json(success_response('', $res));
    }

    /**
     * 查询bi项目配置
     * @param Request $request
     * @return \think\Response
     */
    public function selectConfig(Request $request)
    {
        $res = $this->bIService->selectConfig($request->param());
        return json(success_response('', $res));
    }

    /**
     * 更新bi配置
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function updateConfig(Request $request)
    {
        $param = $request->param()['data'];
        if (!isset($param['config_data'])) {
            throw_strack_exception('config_data require', ErrorCode::REQUEST_PARAM_ERROR);
        }
        $res = $this->bIService->updateConfig($param['project_id'], $param['config_item_name'], $param['config_data'] ?? '');
        return json(success_response('', $res));
    }

    /**
     * 显示项目id列表
     * @param Request $request
     * @return \think\Response
     */
    public function projectShowIdList(Request $request)
    {
        $res = $this->bIService->projectShowIdList();
        return json(success_response('', $res));
    }
}
